package com.probox.common.entity.service.job;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.probox.common.core.enums.PayStatusEnum;
import com.probox.common.entity.domain.job.OrderPayInfo;
import com.probox.common.entity.mapper.job.JobOrderPayInfoMapper;
import com.probox.order.api.domain.OrderQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 付款流水Service业务层处理
 *
 * @author hds
 * @date 2021-06-07
 */
@Service
@Transactional
public class JobOrderPayInfoServiceImpl extends ServiceImpl<JobOrderPayInfoMapper, OrderPayInfo> implements IOrderPayInfoService {

    @Autowired
    private JobOrderPayInfoMapper jobOrderPayInfoMapper;


    @Override
    public OrderPayInfo getByOrderNo(String parentOrderNo) {
        QueryWrapper<OrderPayInfo> queryWrapper = Wrappers.query();
        queryWrapper.eq("PAY_STATUS", PayStatusEnum.paid.getKey());
        queryWrapper.eq("ORDER_NO", parentOrderNo);
        queryWrapper.orderByDesc("CREATE_TIME");
        List<OrderPayInfo> list = jobOrderPayInfoMapper.selectList(queryWrapper);
        if(ObjectUtil.isNotEmpty(list))
            return list.get(0);
        return null;
    }

    @Override
    public Long countAmount(OrderQuery query) {
        return jobOrderPayInfoMapper.countAmount(query);
    }
}
